const UserKey = 'UserKey'
const TokenKey = 'TokenKey'
export function getTokenLocal() {
	return sessionStorage.getItem(TokenKey)
}
export function setTokenLocal(token) {
	return sessionStorage.setItem(TokenKey, token)
}
export function removeTokenLocal() {
	return sessionStorage.removeItem(TokenKey)
}

export function getUserLocal() {
	let str = localStorage.getItem(UserKey)

	try {
		// 尝试解析字符串
		const user = JSON.parse(str);
		// 验证解析结果是否为对象（排除纯数字、布尔值等特殊情况）
		if (typeof user === 'object' && user !== null) {
			return user
		} else {
			return {}
		}
	} catch (e) {
		// 解析失败，不是有效的 JSON 字符串
		return {};
	}
}
export function setUserLocal(user) {
	return localStorage.setItem(UserKey, JSON.stringify(user))
}
export function removeUserLocal() {
	return localStorage.removeItem(UserKey)
}